#ifndef BOARD_H
#define BOARD_H

#include <QWidget>
#include <QMouseEvent>
#include <QPixmap>
#include "stone.h"

class Board : public QWidget
{
    Q_OBJECT
public:
    explicit Board(QWidget *parent = nullptr);

    void paintEvent(QPaintEvent *);         // 绘制事件
    void mousePressEvent(QMouseEvent *);    // 鼠标按下事件，左右键均可
    void mouseReleaseEvent(QMouseEvent *);  // 鼠标松开事件，左右键均可

    bool getRowCol(QPoint pt, int &row, int &col);
    bool getRowCol(int id, int &row, int &col);
    void drawStone(QPainter& painter, int id);

    int relation(int row1, int col1, int row, int col);
    bool isExistStone(int row, int col);
    bool isBottomSide(int id);
    int getStoneCountAtLine(int row1, int col1, int row, int col);

    bool canMove(int moveid, int row, int col, int killid);
    bool canMoveJIANG(int moveid, int row, int col);
    bool canMoveSHI(int moveid, int row, int col);
    bool canMoveXIANG(int moveid, int row, int col);
    bool canMoveCHE(int moveid, int row, int col);
    bool canMoveMA(int moveid, int row, int col);
    bool canMovePAO(int moveid, int row, int col, int killid);
    bool canMoveBING(int moveid, int row, int col);

    // 返回象棋棋盘行列对应的 像素坐标
    QPoint center(int row, int col);
    QPoint center(int id);

    Stone _s[STONE_COUNT];
    int _r; // 棋子的半径
    int _selectid;
    QPoint _startPos;   // 走棋起始位置
    QPoint _endPos;   // 走棋目的位置
    bool _bRedTurn; // 控制该轮到谁走

    QPixmap m_board;
signals:

};

#endif // BOARD_H
